﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Coldairarrow.Util.Excel.Util
{
   public class GlobalUtil
    {
        private const  string  POST_NAME = "__错误信息表";
        public static string GetErrorTableName(string tableName)
        {
            return tableName + POST_NAME;
        }

        public static List<string> GetSame(List<string> modelNames, List<string> importNames)
        {
            List<string> result = new List<string>();
            foreach (var item in modelNames)
            {
                if(importNames.Contains(item))
                {
                    result.Add(item);
                }
            }
            return result;
        }

        public static List<string> GetDifferent(List<string> modelNames, List<string> importNames)
        {
            List<string> result = new List<string>();
            foreach (var item in modelNames)
            {
                if (!importNames.Contains(item))
                {
                    result.Add(item);
                }
            }
            return result;
        }

        public static Dictionary<string, List<string>> GetDifferentList(List<string> modelNames, List<string> importNames)
        {
            Dictionary<string, List<string>> map = new Dictionary<string, List<string>>();
            List<string> result = new List<string>();

            foreach (var item in importNames)
            {
                if (!modelNames.Contains(item))
                {
                    result.Add(item);
                }
            }
            foreach (var item in modelNames)
            {
                if (!importNames.Contains(item))
                {
                    result.Add(item);
                    map.Add(item, result);
                }
            }
            return map;
        }

        /*
        public static List<Dictionary<string, List<string>>> RemoveSame(List<Dictionary<string, List<string>>> list,  bool removeSheet)
        {
            Dictionary<string, List<string>> model = list[0];
            Dictionary<string, List<string>> newModel = new Dictionary<string, List<string>>();
            Dictionary<string, List<string>> imports = list[1];
            Dictionary<string, List<string>> newImports = new Dictionary<string, List<string>>();
            Iterator i$ = model.entrySet().iterator();

            while (true)
            {
                string modelSheetName;
                string sheetName;
                Object modelColumns;
                Object importColumns;
                do
                {
                    if (!i$.hasNext()) {
                        list.clear();
                        list.add(newModel);
                        list.add(newImports);
                        return list;
                    }

                    Entry<string, List<string>> sheet = (Entry)i$.next();
                    modelSheetName = (string)sheet.getKey();
                    sheetName = config.getSheetName(modelSheetName);
                    if (sheetName == null)
                    {
                        sheetName = modelSheetName;
                    }

                    modelColumns = new ArrayList();
                    if (model.get(modelSheetName) != null)
                    {
                        modelColumns = new CopyOnWriteArrayList((Collection)model.get(modelSheetName));
                    }

                    importColumns = new ArrayList();
                    if (imports.get(sheetName) != null)
                    {
                        importColumns = new CopyOnWriteArrayList((Collection)imports.get(sheetName));
                    }

                    Iterator i$ = ((List)modelColumns).iterator();

                    while (i$.hasNext()) {
                        string columnName = (string)i$.next();
                        if (((List)importColumns).contains(columnName))
                        {
                            ((List)modelColumns).remove(columnName);
                            ((List)importColumns).remove(columnName);
                        }
                    }
                } while (((List)modelColumns).size() == 0 && removeSheet);

                newModel.put(modelSheetName, modelColumns);
                newImports.put(sheetName, importColumns);
            }
        }
        */
    }
}
